<?php

class lcarsVList extends lcarsScroller {

	public $vbox;

	public function __construct() {
		parent::__construct();

		$this->vbox = new GtkVBox;
		$this->viewp = new GtkViewport;

		$this->viewp->modify_bg(Gtk::STATE_NORMAL,GdkColor::parse('#000000'));

		$this->viewp->add($this->vbox);
		$this->scrlbox->add($this->viewp);
	
		return;
	}

}

class lcarsInterface extends GtkWindow {

	private $width,$height,$prefullw,$prefullh;
	private $distw,$disth;
	private $fullscreen;
	private $sizeWatch = array();
	private $positionWatch = array();
	
	public $networkBox;
	public $nickBox,$channelBox;

	private $alertStatus;
	private $alertPattern = array('alpha' => array(), 'beta' => array(), 'gamma' => array(), 'tango' => array());
	private $alertTimeout;
	private $alertOffset;
	static $alertPhase = array('#ff0000','#e00000','#dd0000','#c00000','#ffffff');
	
	public $currentChannel;
	
	const WATCH_WIDTH = 1;
	const WATCH_HEIGHT = 2;
	const RED_ALERT = 1;
	const BUTTON = 1;

	public function __construct() {
		parent::__construct();
		
		$this->width = 800;
		$this->height = 600;
		$this->distw = 0;
		$this->disth = 0;		
		$this->fullscreen = false;
		
		$this->alertStatus = false;
		$this->alertTimeout = null;
		$this->alertOffset = 0;
		
		$this->set_position(Gtk::WIN_POS_CENTER);
		$this->set_size_request($this->width,$this->height);
		$this->modify_bg(Gtk::STATE_NORMAL,GdkColor::parse('#000000'));
		$this->connect_simple('delete-event',array($this,'onQuit'));
		$this->connect('configure-event',array($this,'onResize'));
		$this->set_title('LCARS Communications Relay');
		
		$this->networkBox = array();
		$this->hbox = new GtkHBox;
		
		//. lawlllllllllllllll.
		
		$this->col = array(
			'nav1' => new GtkVBox,
			'main' => new GtKVBox		
		);

		$this->col['nav1']->set_size_request(128,-1);
		
		$this->row = array(
			'head' => new GtkHBox		
		);
		
		$this->channelList = new lcarsVList;
		$this->nickList = new lcarsVList;
		
		$this->hfixedr = new GtkFixed;
		$this->hfixedl = new GtkFixed;
		$this->mfixedl = new GtkFixed;

		$this->define = array(

			/*//. server list button title things.
			  ../ these get manually packed.
			  ../ alert pattern gamma and tango. .//*/

			'btn-srvlist' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>24,'id'=>'commnet-btn-server-list','text'=>'srv list','c1'=>'#324aef','ta'=>lcarsButton::RIGHT,'alive'=>false)
			),
			'btn-nicklist' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>24,'id'=>'commnet-btn-nick-list','text'=>'chan data','c1'=>'#324aef','ta'=>lcarsButton::RIGHT,'alive'=>false)
			),

			/*//. build of the 'header' portion of the lcars display.
			  ../ alert pattern alpha. .//*/	
		
			'btn1' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>110,'h'=>42,'id'=>'generic-block-01','text'=>'func01','c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT),
				'container' => $this->hfixedl, 'x' => 0, 'y' => 0,
			),
			'btn-alert' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>110,'h'=>57,'id'=>'commnet-btn-red-alert','text'=>'alert: cond red','c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT,'snd'=>lcars::SND_INIT_CMD),
				'container' => $this->hfixedl, 'x' => 0, 'y' => 44,
			),
			'btn3' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>18,'id'=>'generic-block-03','text'=>'func 03','ts'=>10,'c1'=>'#b0f9fe','ta'=>lcarsButton::RIGHT|lcarsButton::TOP),
				'container' => $this->hfixedl, 'x' => 198, 'y' => 136,
			),
			'btn4' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>75,'h'=>14,'id'=>'generic-block-04','text'=>'','ts'=>10,'c1'=>'#324aef','ta'=>lcarsButton::RIGHT|lcarsButton::TOP,'alive'=>false),
				'container' => $this->hfixedl, 'x' => 300, 'y' => 136,
			),
			'btn-fullscreen' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>18,'id'=>'commnet-btn-fullscreen-toggle','text'=>'fullscreen','ts'=>10,'c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT|lcarsButton::TOP),
				'container' => $this->hfixedl, 'x' => 377, 'y' => 136,
			),
			'btn6' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>192,'h'=>18,'id'=>'generic-block-06','text'=>'','ts'=>10,'c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT|lcarsButton::TOP,'alive'=>false),
				'container' => $this->hfixedl, 'x' => 479, 'y' => 136,
			),
			'bend01' => array(
				'type' => 'button',
				'btntype' => EXECROOT.lcars::UI_DIR.'/lcars-bend-01.png',
				'opts' => array('id'=>'commnet-bend-01','alive'=>false),
				'container' => $this->hfixedl, 'x' => 0, 'y' => 103			
			),
			'title' => array(
				'type' => 'button',
				'btntype' => EXECROOT.lcars::UI_DIR.'/lcars-title-01.png',
				'opts' => array('id'=>'commnet-title','alive'=>false),
				'container' => $this->hfixedr, 'x' => 0, 'y' => 0
			),
			
			/*//. build of the 'main' portion of the lcars display.
			  ../ alert pattern beta. .//*/
			'bend02' => array(
				'type' => 'button',
				'btntype' => EXECROOT.lcars::UI_DIR.'/lcars-bend-02.png',
				'opts' => array('id'=>'commnet-bend-02','alive'=>false),
				'container' => $this->mfixedl, 'x' => 0, 'y' => 0			
			),
			'btn7' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>24,'id'=>'generic-block-07','text'=>'func 07','ts'=>10,'c1'=>'#324aef','ta'=>lcarsButton::RIGHT|lcarsButton::TOP),
				'container' => $this->mfixedl, 'x' => 198, 'y' => 0,
			),
			'btn-chnick' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>75,'h'=>32,'id'=>'commnet-btn-change-nick','text'=>'bob','ts'=>10,'c1'=>'#324aef','ta'=>lcarsButton::RIGHT|lcarsButton::TOP),
				'container' => $this->mfixedl, 'x' => 300, 'y' => -4,
			),
			'btn8' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>100,'h'=>24,'id'=>'generic-block-08','text'=>'func 08','ts'=>10,'c1'=>'#324aef','ta'=>lcarsButton::RIGHT|lcarsButton::TOP),
				'container' => $this->mfixedl, 'x' => 377, 'y' => 0,
			),
			'btn10' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>192,'h'=>18,'id'=>'generic-block-10','text'=>'','c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT,'alive'=>false),
				'container' => $this->mfixedl, 'x' => 479, 'y' => 0,
			),
			'btn-channel' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>110,'h'=>32,'id'=>'commnet-btn-display-channel','text'=>'no chnl','ts'=>11,'c1'=>'#b0f9fe','ta'=>lcarsButton::RIGHT),
				'container' => $this->mfixedl, 'x' => 0, 'y' => 96,
			),
			'btn-part' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>110,'h'=>32,'id'=>'commnet-btn-part-channel','text'=>'leave chnl','c1'=>'#eeeef2','ta'=>lcarsButton::RIGHT),
				'container' => $this->mfixedl, 'x' => 0, 'y' => 130,
			),
			'btn11' => array(
				'type' => 'button',
				'btntype' => lcarsButton::TYPE_BLOCK,
				'opts' => array('w'=>110,'h'=>278,'id'=>'generic-block-11','text'=>'func11','ta'=>lcarsButton::RIGHT),
				'container' => $this->mfixedl, 'x' => 0, 'y' => 164,
			),
			'btn-send' => array(
				'type' => 'button',
				'btntype' => EXECROOT.lcars::UI_DIR.'/lcars-btn-03.png',
				'opts' => array('w'=>53,'h'=>32,'id'=>'commnet-btn-send-message','text'=>'tx','c1'=>'#f4c179'),
				'container' => $this->mfixedl, 'x' => 617, 'y' => 408,
				'watch-position' => (self::WATCH_WIDTH | self::WATCH_HEIGHT)
			),
		);

		foreach($this->define as $id => $w) {
			if($w['type'] == 'button') {
				$this->img[$id] = new lcarsButton(
					$w['btntype'],
					$w['opts']			
				);
			}
			
			if(array_key_exists('watch-position',$w)) {
				$this->img[$id]->setPosition($w['container'],$w['x'],$w['y']);
			} else if(array_key_exists('container',$w)) {
				$w['container']->put($this->img[$id],$w['x'],$w['y']);
			}
		} unset($id,$w);
		
		
		$this->img['btn-fullscreen']->connect_simple_after('button-release-event',array($this,'toggleFullscreen'));
		$this->img['btn-alert']->connect_simple_after('button-release-event',array($this,'toggleRedAlert'));
		$this->img['btn-send']->connect_simple_after('button-release-event',array($this,'sendMessage'));
		$this->img['btn-part']->connect_simple_after('button-release-event',array('ircEvent','runCommand'),'part');		

		$this->text1 = new lcarsTextView('#5292ef');
		$this->text1->setSize(554,95);
		$this->hfixedl->put($this->text1,120,28);
			
		$this->text2 = new lcarsTextView;
		$this->text2->setSize(554,370);
		$this->mfixedl->put($this->text2,120,28);
		
		$this->input = new lcarsEntry;
		$this->input->setSize(495,32);
		$this->input->setPosition($this->mfixedl,120,408);
		$this->input->connect_simple('activate',array($this,'sendMessage'));		

		/*//. manage constraints
		  ../ resize or reposition widgets on window resize. .//*/

		$this->sizeWatch = array(
			array($this->img['btn6'],self::WATCH_WIDTH),
			array($this->img['btn10'],self::WATCH_WIDTH),
			array($this->img['btn11'],self::WATCH_HEIGHT),
			array($this->text1,self::WATCH_WIDTH),
			array($this->text2,self::WATCH_WIDTH|self::WATCH_HEIGHT),
			array($this->input,self::WATCH_WIDTH)
		);
		
		$this->positionWatch = array(
			array($this->input,self::WATCH_HEIGHT,$this->mfixedl),
			array($this->img['btn-send'],self::WATCH_WIDTH|self::WATCH_HEIGHT,$this->mfixedl)	
		);

		/*//. manage alert patterns
		  ../ blinky blinky is teh shizzor. .//*/
		
		$this->alertPattern = array(
			'alpha' => array(
				$this->img['btn1'], $this->img['btn-alert'], $this->img['bend01'], $this->img['btn3'],
				$this->img['btn4'], $this->img['btn-fullscreen'],	$this->img['btn6']		
			),

			'beta' => array( 
				$this->img['btn11'], $this->img['btn-part'], $this->img['btn-channel'],
				$this->img['bend02'], $this->img['btn7'], $this->img['btn-chnick'], $this->img['btn8'],
				$this->img['btn10'], $this->img['btn-send']		
			),
			
			'gamma' => array(
				$this->img['btn-srvlist']			
			),
			
			'tango' => array(
				$this->img['btn-nicklist']
			)
		);
		
		$this->alertPattern['alpha'] = array_reverse($this->alertPattern['alpha']);
		$this->alertPattern['beta'] = array_reverse($this->alertPattern['beta']);

		/*//. packing the main window widgets.
		  ../ boom, headshot. .//*/

		$this->col['nav1']->pack_start($this->img['btn-srvlist'],false,false,0);
		$this->col['nav1']->pack_start($this->channelList,true,true,0);
		$this->col['nav1']->pack_start($this->img['btn-nicklist'],false,false,0);		
		$this->col['nav1']->pack_start($this->nickList,true,true,0);
		
		$this->row['head']->pack_start($this->hfixedl,false,false,0);
		$this->row['head']->pack_end($this->hfixedr,false,false,0);
		
		$this->col['main']->pack_start($this->row['head'],false,false,0);
		$this->col['main']->pack_start($this->mfixedl,false,false,2);
				
		$this->hbox->pack_start($this->col['nav1'],false,false,0);
		$this->hbox->pack_start($this->col['main'],true,true,0);
		
		//. end lawlllllllllllllll.
		
		$this->add($this->hbox);
		$this->show_all();
		return;
	}
	
	public function temp_text_blah($buffer) {
		if(!array_key_exists('omfg',$this) || $this->omfg == null) {
			$this->omfg = fopen(EXECROOT.'/usr/libexec/commnet/lcars-button.so.php','r');
		}
		
		if($dump = fgets($this->omfg)) {
			$buffer->append($dump);
		} else {
			fclose($this->omfg);
			$this->omfg = null;
		}
		
		return true;
	}
	
	public function sendMessage() {
		if(($text = $this->input->get_text())) {
			if(substr($text,0,1) != '/' || substr($text,0,2) == '//') {
				if($this->currentChannel->channel == 'null') {
					ircEvent::runCommand("join {$text}");
				} else {
					ircEvent::runCommand("msg {$this->currentChannel->channel} {$text}");
				}			
			} else {
				ircEvent::runCommand($text);
			}
			
			$this->img['btn-send']->onMouseDown();
			Gtk::timeout_add(200,array($this->img['btn-send'],'onMouseUp'));
			lcars::killTime();
		
			$this->input->set_text('');
		}
		return;
	}
	
	public function addNetworkButton($network) {
		$this->networkBox[$network->network] = new GtkVBox;
		$this->channelBox[$network->network] = new GtkVBox;
		$button = new lcarsButton(
			lcarsButton::TYPE_BLOCK,
			array(
				'id' => 'commnet-irc-buttons-server-'.strtolower($network->network),
				'text' => $network->network,
				'ts' => 10,
				'w' => 99, 'h' => 14
			)
		);
		
		$button->connect_simple_after('button-release-event',array($this,'setActiveChannel'),$network->channel['null']);

		$this->alertPattern['gamma'][] = $button;
		$this->networkBox[$network->network]->pack_start($button,false,false,0);
		$this->networkBox[$network->network]->pack_start($this->channelBox[$network->network],false,false,1);
		$this->channelList->vbox->pack_start($this->networkBox[$network->network],false,false,0);		
		
		return $button;
	}

	public function addChannelButton($channel) {
		$button = new lcarsButton(
			lcarsButton::TYPE_BLOCK,
			array(
				'id' => 'commnet-irc-button-channel-'.strtolower($channel->channel),
				'text' => $channel->channel,
				'ts' => 10,
				'ta' => lcarsButton::RIGHT,
				'w' => 99, 'h' => 14
			)
		);

		$button->connect_simple_after('button-release-event',array($this,'setActiveChannel'),$channel);

		$this->alertPattern['gamma'][] = $button;
		$this->nickBox["{$channel->network->network}-{$channel->channel}"] = new GtkVBox;
		$this->nickBox["{$channel->network->network}-{$channel->channel}"]->hide();
		$this->nickList->vbox->pack_start($this->nickBox["{$channel->network->network}-{$channel->channel}"],false,false,0);
		$this->channelBox[$channel->network->network]->pack_start($button,false,false,0);
		$this->channelBox[$channel->network->network]->show_all();
		lcars::killTime();		
		return $button;
	}
	
	public function addNickButton($channel,$nick) {
		$button = new lcarsButton(
			lcarsButton::TYPE_BLOCK,
			array(
				'id' => 'commnet-irc-button-nick-'.strtolower($nick),
				'text' => $nick,				
				'ts' => 10,
				'ta' => lcarsButton::RIGHT,
				'w' => 99, 'h' => 14,
				'alive'=>false
			)
		);
		
		$this->alertPattern['tango'][] = $button;
	
		$this->nickBox["{$channel->network->network}-{$channel->channel}"]->pack_start($button,false,false,1);
		$this->nickBox["{$channel->network->network}-{$channel->channel}"]->show_all();
		lcars::killTime();		
		return $button;	
	}
	
	public function sortNetworkList() {
		ksort(commnet::$network);
		foreach(commnet::$network as $id => $network) {
			if(!array_key_exists($id,$this->networkBox)) { continue; }
			$this->channelList->vbox->remove($this->networkBox[$id]);
			$this->channelList->vbox->pack_start($this->networkBox[$id],false,false,2);
			$this->channelList->vbox->show_all();
		}
		return;
	}
	
	public function sortChannelList($channel) {
		ksort($channel->network->channel,SORT_STRING);
		foreach($channel->network->channel as $id => $channel) {
			if($channel->channel == 'null') { continue; }
			echo("$id\n");
			$this->channelBox[$channel->network->network]->remove($channel->button);
			$this->channelBox[$channel->network->network]->pack_start($channel->button,false,false,2);
		}	
	}
	
	public function sortNickList($channel) {
		ksort($channel->nicklist,SORT_STRING);
		foreach($channel->nicklist as $id => $nick) {
			$this->nickBox["{$channel->network->network}-{$channel->channel}"]->remove($nick->button);
			$this->nickBox["{$channel->network->network}-{$channel->channel}"]->pack_start($nick->button,false,false,2);
		}
		return;
	}
	
	public function onResize($w,$e) {
		if(get_class($w) != 'lcarsInterface') { return; }
		list($w,$h) = $this->get_size();

		if($w == $this->width && $h == $this->height) {
			return;
		}
		
		if($w != $this->width) {
			$this->distw = $w - $this->width;
			$this->width = $w;
//			echo("window changed width: {$this->distw}\n");
		}

		if($h != $this->height) {
			$this->disth = $h - $this->height;
			$this->height = $h;
//			echo("window changed height: {$this->disth}\n");
		}

		if($this->distw || $this->disth) {
			$this->runResize();
			$this->runPosition();
			$this->text1->scrollToBottom();
			$this->text2->scrollToBottom();
		} $this->distw = $this->disth = 0;
		lcars::killTime();
		
		return ;
	}
	
	public function onQuit() {
		$this->hide();
		Gtk::main_quit();
		return;
	}
	
	public function runResize() {

		foreach($this->sizeWatch as $id => $item) {
			$go = false;
			list($w,$h) = $item[0]->getSize();
			
			if($this->distw && $item[1] & self::WATCH_WIDTH) {
				$w += $this->distw;
				$go = true;
			}
			if($this->disth && $item[1] & self::WATCH_HEIGHT) {
				$h += $this->disth;
				$go = true;
			}
			
			if($go) {
//				echo("resizing {$id} to {$w} {$h}\n");
				$item[0]->setSize($w,$h);
			}
		}		

		return;
	}
	
	public function runPosition() {

		foreach($this->positionWatch as $id => $item) {
			$go = false;
			list($x,$y) = $item[0]->getPosition();
			
			if($this->distw && $item[1] & self::WATCH_WIDTH) {
				$x += $this->distw;
				$go = true;
			}
			if($this->disth && $item[1] & self::WATCH_HEIGHT) {
				$y += $this->disth;
				$go = true;
			}
			
			if($go) {
//				echo("moving {$id} to {$x} {$y}\n");
				$item[0]->setPosition($item[2],$x,$y,true);
			}
		}		
	
		return;
	}
	
	public function toggleFullscreen() {

		if($this->fullscreen) {
			$this->set_decorated(true);
			$this->resize($this->prefullw,$this->prefullh);
			
			lcars::killTime();
			$this->set_position(Gtk::WIN_POS_CENTER);
			$this->set_keep_above(false);
			lcars::killTime();
			
			$this->img['btn-fullscreen']->setAttn(false);
			$this->fullscreen = false;
		} else {
			$this->prefullw = $this->width;
			$this->prefullh = $this->height;

			$root = Gdk::get_default_root_window();
			list($w,$h) = $root->get_size();
			
			$this->set_decorated(false);
			lcars::killTime();
			
			$this->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
			lcars::killTime();
			
//			$this->set_keep_above(true);
			
			lcars::killTime();
			$this->resize($w,$h);
			lcars::killTime();
			
			$this->img['btn-fullscreen']->setAttn(true);
			$this->fullscreen = true;
		}

		return;
	}
	
	public function toggleRedAlert() {
		if($this->alertStatus == self::RED_ALERT) {
			$this->setAlertStatus(false);
		} else {
			$this->setAlertStatus(self::RED_ALERT);
		}
		
		return;
	}
	
	public function setAlertStatus($type,$rate = 800) {
	
		$this->alertStatus = $type;
		
		if($type && !lcars::$redAlert) {
			lcars::$sndsrc['klaxon']->play();
			if(!lcars::$sndsrcTimeout['klaxon']) {
				lcars::$sndsrcTimeout['klaxon'] = Gtk::timeout_add(60000,array($this,'runSound'),lcars::$sndsrc['klaxon']);
			}			
			
			$this->img['btn-alert']->setText('cncl red alert');
			lcars::$redAlert = true;
			$this->runAlert(true);
			$this->img['title']->setBlink(lcarsInterface::$alertPhase[0],lcarsInterface::$alertPhase[4]);
			$this->text1->setColour(lcarsInterface::$alertPhase[4]);
			$this->text2->setColour(lcarsInterface::$alertPhase[0]);
			$this->input->setColour(lcarsInterface::$alertPhase[0]);
			$this->alertTimeout = Gtk::timeout_add($rate,array($this,'runAlert'));
		} else if(!$type && lcars::$redAlert) {
			if($this->alertTimeout) {
				Gtk::timeout_remove($this->alertTimeout);
				$this->alertTimeout = null;
			}

			lcars::$sndsrc['klaxon']->stop();
			if(lcars::$sndsrcTimeout['klaxon']) {
				Gtk::timeout_remove(lcars::$sndsrcTimeout['klaxon']);
			}
			
			$this->img['btn-alert']->setText('alert: cond red');
			lcars::$redAlert = false;
			$this->runAlert(null);
			$this->img['title']->setBlink(false,false);
			$this->text1->setColour(false);
			$this->text2->setColour(false);
			$this->input->setColour(false);
			$this->alertOffset = 0;
		}
	
		return;
	}
	
	public function runAlert($force = false) {

		$count = count(lcarsInterface::$alertPhase);
		if($this->alertOffset == $count) {
			$this->alertOffset = 0;
		}
		
		foreach($this->alertPattern as $id => &$list) {
			$a = $this->alertOffset;
			
			foreach($list as $iter => $element) {

				if($force === false) {
					$element->setColour(lcarsInterface::$alertPhase[$a++]);	
					if($a == $count) { $a = 0; }
				}
				
				else if($force === true) {
					$element->setColour(lcarsInterface::$alertPhase[0]);	
				}
				
				else  if($force === null) {
					$element->setColour(false);
				}
			}
		} lcars::killTime();	
		
		if($force == false) { ++$this->alertOffset; }	
		return true;
	}
	
	public function runSound($src) {
		$src->play();
		return true;
	}
	
	public function setActiveChannel($channel) {

		if($this->currentChannel && $this->currentChannel->channel != 'null') {
			$this->nickBox["{$this->currentChannel->network->network}-{$this->currentChannel->channel}"]->hide();
		}

		if(is_object($channel)) {

			if(array_key_exists(strtolower($channel->network->whoami),$channel->nicklist)) {
				$this->img['btn-chnick']->setColour(ircNick::colour($channel->nicklist[strtolower($channel->network->whoami)]->mode));
			} else {
				$this->img['btn-chnick']->setColour(ircNick::colour(ircNick::NORMAL));
			}

			if($channel->channel != 'null') {
				$this->nickBox["{$channel->network->network}-{$channel->channel}"]->show_all();
				$this->img['btn-channel']->setText($channel->channel);
				$this->img['btn-chnick']->setText($channel->network->whoami);
				$this->img['btn-part']->setText('leave chnl');
				$this->img['btn-send']->setText('tx');
				$channel->button->setAttn(false);
			} else {
				$this->img['btn-channel']->setText('no chnl');
				$this->img['btn-chnick']->setText($channel->network->whoami);
				$this->img['btn-part']->setText('disconnect');
				$this->img['btn-send']->setText('join');
			}
			
			$this->currentChannel = $channel;
			$this->text2->setTerminal($channel->terminal);
			$this->text2->scrollToBottom();
		} else {
			$this->img['btn-channel']->setText('no chnl');		
		}
		return;
	}
	
}

?>